<?php

class Webmix_Form_Admin_Webmix_Filter extends Engine_Form
{
  public function init()
  {
    $this
      ->clearDecorators()
      ->addDecorator('FormElements')
      ->addDecorator('Form')
      ->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'search'))
      ->addDecorator('HtmlTag2', array('tag' => 'div', 'class' => 'clear'))
      ;

    $this
      ->setAttribs(array(
        'id' => 'filter_form',
        'class' => 'global_form_box',
      ))
      ->setMethod('GET');

    $title = new Zend_Form_Element_Text('title');
    $title
      ->setLabel('Title')
      ->clearDecorators()
      ->addDecorator('ViewHelper')
      ->addDecorator('Label', array('tag' => null, 'placement' => 'PREPEND'))
      ->addDecorator('HtmlTag', array('tag' => 'div'));
	$owner = new Zend_Form_Element_Text('owner');
    $owner
      ->setLabel('Owner')
      ->clearDecorators()
      ->addDecorator('ViewHelper')
      ->addDecorator('Label', array('tag' => null, 'placement' => 'PREPEND'))
      ->addDecorator('HtmlTag', array('tag' => 'div'));
      
     $countryTB = Engine_Api::_()->getDbTable('countries','webmix');
        $countries = $countryTB->fetchAll($countryTB->select()->where('selected =1'));  
        $country_prepare = array('0' => 'All');
        foreach($countries as $country){
            $country_prepare[$country->country_id] = $country->title;
        }    
    $country = new Zend_Form_Element_Select('country');
    $country
      ->setLabel('Country')
      ->clearDecorators()
      ->addDecorator('ViewHelper')
      ->addDecorator('Label', array('tag' => null, 'placement' => 'PREPEND'))
      ->addDecorator('HtmlTag', array('tag' => 'div'))
      ->addMultiOptions($country_prepare);
      
    $submit = new Zend_Form_Element_Button('search', array('type' => 'submit'));
    $submit
      ->setLabel('Search')
      ->clearDecorators()
      ->addDecorator('ViewHelper')
      ->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'buttons'))
      ->addDecorator('HtmlTag2', array('tag' => 'div'));


   $createby = new Zend_Form_Element_Select('createby');
    $createby
      ->setLabel('Create by')
      ->clearDecorators()
      ->addDecorator('ViewHelper')
      ->addDecorator('Label', array('tag' => null, 'placement' => 'PREPEND'))
      ->addDecorator('HtmlTag', array('tag' => 'div'))
       ->setMultiOptions(array(''=>'All', 'user' => 'User', 'system' => 'System'));
       
    $this->addElement('Hidden', 'order', array(
      'order' => 10001,
    ));

    $this->addElement('Hidden', 'order_direction', array(
      'order' => 10002,
    ));

    $this->addElement('Hidden', 'webmix_id', array(
      'order' => 10003,
    ));

    
    $this->addElements(array(
      $title,
      $owner,
      $country,
      $createby,      
      $submit,
    ));

    // Set default action without URL-specified params
    $params = array();
    foreach (array_keys($this->getValues()) as $title) {
      $params[$title] = null;
    }
    $this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble($params));
  }
}